package kr.co.ljw.refactoring;

import java.util.Enumeration;
import java.util.Vector;

/**
 * customer
 * 
 * @author 오스템임플란트 jw
 * @since 2013. 1. 2.
 * @version 1.0
 * @see
 * 
 * <pre>
 * << 개정이력(Modification Information) >>
 *   
 *	  수정일  		수정자				수정내용		
 *	----------		------		------------------------
 *	2013. 1. 2.    jw				최초 생성
 *
 * </pre>
 */
public class Customer {
	private	String	_name;
	private	Vector	_rentals = new Vector();
	
	public Customer(String name){
		_name = name;
	}
	
	public void addRental(Rental arg){
		_rentals.addElement(arg);
	}
	
	public String getName(){
		return _name;
	}
	
	//명세서 text version 
	public String statement(){
		
		int frequentRenterPoints = 0;
		Enumeration rentals = _rentals.elements();
		String result = "Rental Record for " + getName() + "\n";
		while(rentals.hasMoreElements()){
			Rental each = (Rental)rentals.nextElement();
			 
			 //이 대여에 대한 요금 계산결과 표시
			 result += "\t" + each.getMovie().getTitle() + "\t" +
					 String.valueOf(each.getCharge()) + "\n";
		}
		
		//풋터(footer)추가
		result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
		result += "You earned " + String.valueOf(getTotalFrequentRenterPoints()) + " frequent renter points";
		
		return result;
	}
	
	//명세서 html version
	public String htmlStatement(){
		Enumeration rentals = _rentals.elements();
		String result = "<H1>Rentals for <EM>" + getName() + "</EM></H1><P>\n";
		while(rentals.hasMoreElements()){
			Rental each = (Rental)rentals.nextElement();
			
			//이 대에 대한 요금 계산결과 표시
			result += each.getMovie().getTitle() + ": " +
					  String.valueOf(each.getCharge()) + "<BR>\n";		
		}
		//풋터(fotter)추가
		result += "<P>You owe <EM>" + String.valueOf(getTotalCharge()) + "</EM><P>\n";
		result += "On this rental you earned <EM>" +
				  String.valueOf(getTotalFrequentRenterPoints()) +
				  "</EM> frequent renter points<P>";
		return result;
	}
	
	//전체 요금 계산
	public double getTotalCharge(){
		double result = 0;
		Enumeration rentals = _rentals.elements();
		while(rentals.hasMoreElements()){
			Rental each = (Rental)rentals.nextElement();
			result += each.getCharge();
		}
		return result;
	}
	
	//포인트 계산
	public int getTotalFrequentRenterPoints(){
		int result = 0;
		Enumeration rentals = _rentals.elements();
		while(rentals.hasMoreElements()){
			Rental each = (Rental)rentals.nextElement();
			result += each.getFrequentRenterPoints();
		}
		return result;
	}
}